package com.qsl.ssyx.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.sys.mapper.RegionWareMapper;
import com.qsl.ssyx.model.sys.RegionWare;
import com.qsl.ssyx.sys.service.RegionWareService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.ssyx.vo.sys.RegionWareQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 城市仓库关联表 服务实现类
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-08
 */
@Service
public class RegionWareServiceImpl extends ServiceImpl<RegionWareMapper, RegionWare> implements RegionWareService {

    //    条件分页查询
    @Override
    public IPage<RegionWare> selectPage(Page<RegionWare> pageParam, RegionWareQueryVo regionWareQueryVo) {
        LambdaQueryWrapper<RegionWare> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(regionWareQueryVo.getKeyword())) {
            lqw.like(RegionWare::getRegionName, regionWareQueryVo.getKeyword()).or().like(RegionWare::getWareName, regionWareQueryVo.getKeyword());
        }
        lqw.orderByDesc(RegionWare::getId); //倒序排序

        Page<RegionWare> regionWarePage = baseMapper.selectPage(pageParam, lqw);
        return regionWarePage;
    }

    // 取消开通
    @Override
    public boolean updateStatus(Long id, Integer status) {
        RegionWare regionWare = new RegionWare();
        regionWare.setId(id);
        regionWare.setStatus(status);
        System.out.println("@523525");
        int i = baseMapper.updateById(regionWare);
        return i > 0;
    }
}
